package com.lorgeoux.android.parking.service;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.Menu;
import android.view.MenuItem;

import com.lorgeoux.android.ParkingNantesActivity;
import com.lorgeoux.android.R;

public class ServiceMenu {

	private static final int MENU_QUITTER = 200;
	private static final int MENU_A_PROPOS = 100;

	public static boolean initialiserMenu(Menu menu) {
		menu.add(0, MENU_QUITTER, 0, "Quitter");
		menu.add(1, MENU_A_PROPOS, 0, "A propos");
		return true;
	}

	public static boolean traiterClicMenu(MenuItem item,
			ParkingNantesActivity parkingNantesActivity) {
		switch (item.getItemId()) {
		case MENU_A_PROPOS:
			evenementAPropos(parkingNantesActivity);
			return true;
		case MENU_QUITTER:
			evenementQuitter(parkingNantesActivity);
			return true;
		}
		return false;
	}

	private static void evenementQuitter(
			ParkingNantesActivity parkingNantesActivity) {
		parkingNantesActivity.finish();
        System.runFinalizersOnExit(true);
        System.exit(0);
	}

	private static void evenementAPropos(
			ParkingNantesActivity parkingNantesActivity) {
		
		AlertDialog.Builder builder = new AlertDialog.Builder(parkingNantesActivity);
		builder.setTitle("A Propos")
				.setMessage(R.string.texteAPropos)
				.setCancelable(true);
		AlertDialog alert = builder.create();
		alert.setButton("Fermer", new DialogInterface.OnClickListener() {
		      public void onClick(DialogInterface dialog, int which) {
		       } });
		alert.show();
	}

}
